博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
导航和渲染首页文章列表
阅读量:6883 次
发布时间:2019-06-27

本文共 3022 字,大约阅读时间需要 10 分钟。

导航的逻辑是判断用户是否登录,登录了显示登录看到的信息,没登录显示注册和登录。

 

渲染文章列表需要先注册admin,然后在admin里加入几篇文章,然后在视图函数里提取文章数据,并渲染到模板。需要注意的是显示用户头像的时候,需要在用户头像路径前加上media/

 

index.py和logout.py

# 首页def index(request):    article_list = models.Article.objects.all()    context = {        'article_list': article_list,    }    return render(request, 'index.html', context=context)# 注销def logout(request):    auth.logout(request)  # request.session.flush()    return redirect(reverse('blog:login'))

 

index.html

    
index
Panel heading without title
Panel content
Panel heading without title
Panel content
Panel heading without title
Panel content
{% for article in article_list %}
{ { article.title }}
avatar
{ { article.desc }}
{ { article.user.username }}
发布于{ { article.created_time | date:'Y-m-d H:i' }}
评论{ { article.comment_count }}
点赞{ { article.up_count }}

{% endfor %}
Panel heading without title
Panel content
Panel heading without title
Panel content

 

 

转载于:https://www.cnblogs.com/lshedward/p/10387619.html

你可能感兴趣的文章
自己动手写插件底层篇—基于jquery移动插件实现
查看>>
一天干掉一只Monkey计划(序)【转】
查看>>
C++11中的原子操作(atomic operation)(转)
查看>>
std::nothrow
查看>>
通俗讲解:PoW共识机制与以太坊的关系、Ghost协议 及 PoS共识机制的变种---Casper...
查看>>
给想雇佣我的人说的话/Some words to somebody who want to hire me.
查看>>
网站程序(案例)
查看>>
spring依赖注入单元测试:expected single matching bean but found 2
查看>>
ubuntu下安装xlrd模块,Mysqldb模块
查看>>
Git_自定义Git
查看>>
js手机适配
查看>>
软件测试书籍推荐
查看>>
[linux]执行pip安装的程序:command not found
查看>>
dcm4che tools 之dicomdir
查看>>
HDU 4849-Wow! Such City!(最短路)
查看>>
关于IM的一些思考与实践
查看>>
SimInfo获取(MCC, MNC, PLMN)
查看>>
[置顶] 我的Android进阶之旅------>介绍一款集录制与剪辑为一体的屏幕GIF 动画制作工具 GifCam...
查看>>
IMP导入数据 出现ORA-01691问题 解决办法
查看>>
dll常规安装方法
查看>>